import { Body, Get, Inject, Post, Query } from "@midwayjs/core";
import { ProviderLoginService } from "../../service/login";
import { BaseController, CoolController, CoolTag, CoolUrlTag, TagTypes } from "@cool-midway/core";
import { BaseSysLoginService } from "../../../base/service/sys/login";

@CoolUrlTag()
@CoolController()
export class ProviderLoginController extends BaseController {

    @Inject()
    providerLoginService: ProviderLoginService

    @Inject()
    baseSysLoginService: BaseSysLoginService



    @CoolTag(TagTypes.IGNORE_TOKEN)
    @Post('/phone', { summary: '手机号登录' })
    async phone(@Body('phone') phone: string, @Body('smsCode') smsCode: string) {
        return this.ok(await this.providerLoginService.phoneVerifyCode(phone, smsCode));
    }

    // @CoolTag(TagTypes.IGNORE_TOKEN)
    // @Post('/uniPhone', { summary: '一键手机号登录' })
    // async uniPhone(
    //     @Body('access_token') access_token: string,
    //     @Body('openid') openid: string,
    //     @Body('appId') appId: string
    // ) {
    //     return this.ok(
    //         await this.providerLoginService.uniPhone(access_token, openid, appId)
    //     );
    // }

    // @CoolTag(TagTypes.IGNORE_TOKEN)
    // @Post('/miniPhone', { summary: '绑定小程序手机号' })
    // async miniPhone(@Body() body) {
    //     const { code, encryptedData, iv } = body;
    //     return this.ok(
    //         await this.providerLoginService.miniPhone(code, encryptedData, iv)
    //     );
    // }

    @CoolTag(TagTypes.IGNORE_TOKEN)
    @Get('/captcha', { summary: '图片验证码' })
    async captcha(
        @Query('width') width: number,
        @Query('height') height: number,
        @Query('color') color: string
    ) {
        return this.ok(
            await this.baseSysLoginService.captcha(width, height, color)
        );
    }

    @CoolTag(TagTypes.IGNORE_TOKEN)
    @Post('/smsCode', { summary: '验证码' })
    async smsCode(
        @Body('phone') phone: string,
        @Body('captchaId') captchaId: string,
        @Body('code') code: string
    ) {
        return this.ok(await this.providerLoginService.smsCode(phone, captchaId, code));
    }

    @CoolTag(TagTypes.IGNORE_TOKEN)
    @Post('/refreshToken', { summary: '刷新token' })
    public async refreshToken(@Body('refreshToken') refreshToken) {
        return this.ok(await this.providerLoginService.refreshToken(refreshToken));
    }

    // @CoolTag(TagTypes.IGNORE_TOKEN)
    // @Post('/password', { summary: '密码登录' })
    // async password(
    //     @Body('phone') phone: string,
    //     @Body('password') password: string
    // ) {
    //     return this.ok(await this.providerLoginService.password(phone, password));
    // }

}